package dshop.model.member;

import java.util.List;

import com.jfinal.plugin.activerecord.Record;

import appbase.jfinal.ext.BaseModel;

public class MemberCompany extends BaseModel<MemberCompany>{
	
	private static final long serialVersionUID = -6967680902549117464L;
	
	public static final MemberCompany dao = new MemberCompany();

	/**
	 * @return [{ .., company_id }]
	 */
	public static void setCompanyIdToRs(List<Record> list, String accountIdColumn) 
	{
		dao.mergeColumnsToRs(list, accountIdColumn, "account_id", "account_id, company_id", "company_id", null);
	}

	public static boolean isExist(int companyId, int accountId) 
	{
		return dao.exist("account_id, company_id", accountId, companyId);
	}

	public static Integer getCompanyId(int accountId) 
	{
		MemberCompany mc = dao.findFirstByColumns("company_id", "account_id", accountId);
		if (mc == null)
		{
			return null; 
		}
		return mc.getInt("company_id");
	}

	
	
}
